package com.example.client.service.impl;

import com.example.client.domain.Address;
import com.example.client.mapper.AddressMapper;
import com.example.client.pojo.Code;
import com.example.client.pojo.Result;
import com.example.client.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddressServiceImpl implements AddressService {

    @Autowired
    private AddressMapper addressMapper;

    @Override
    public Result<List<Address>> getAddresses(String username) {
        List<Address> addresses = addressMapper.selectAddressesByUserName(username);
        return new Result<List<Address>>(addresses, Code.RESPONSE_CODE_SUCCESS, "查询成功");
    }

    @Override
    public Result updateAddressByAddressId(Address address, Integer address_id) {
        addressMapper.updateAddressByAddressId(address.getAddress(), address_id);
        return new Result<>(Code.RESPONSE_CODE_SUCCESS, "修改成功");
    }

    @Override
    public Result insertAddress(Address address, String username) {
        addressMapper.insertAddress(address.getAddress(), username);
        return new Result<>(Code.RESPONSE_CODE_SUCCESS, "添加成功");
    }

    @Override
    public Result deleteAddress(Integer address_id) {
        addressMapper.deleteAddressByAddressId(address_id);
        return new Result<>(Code.RESPONSE_CODE_SUCCESS, "删除成功");
    }
}
